package org.test.cloud.stream.rocketmq.controller;

import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class MessageProducerController {

    @Resource
    private StreamBridge streamBridge;

    @PostMapping("/send")
    public String sendMessage(@RequestBody String message) {
        streamBridge.send("streamProducer", MessageBuilder.withPayload(message).build());
        return "Message sent: " + message;
    }
}
